﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace newTurtle8
{
    public class Tahasuka : Mofa
    {
        public Tahasuka(DateTime start, DateTime end, bool isCreation)
            : base(start, end, "TahasukaData", "TahasukaZimunim", isCreation)  
        {
            if (isCreation)
            {
                SqlCommand insertCmd = SqlManager.getSqlCommandFromFile(@"\INSERT\TahasukaSiurKav.INSERT.sql");
                insertCmd.Parameters.Add("@startDate", SqlDbType.Date).Value = startDate;
                SqlManager.executeNonQuery(insertCmd);
            }
        }

        override public void addSoldier(List<string> armyIdList) 
        {
           foreach (string armyID in armyIdList)
           {
               //add entry to TahasukaAlal Table
               SqlCommand insertAlalCmd = SqlManager.getSqlCommandFromFile(@"\INSERT\TahasukaAlal.INSERT.sql");
               insertAlalCmd.Parameters.Add("@startDate", SqlDbType.Date).Value = startDate;
               insertAlalCmd.Parameters.Add("@armyID", SqlDbType.NVarChar).Value = armyID;
               insertAlalCmd.Parameters.Add("@dayShoot", SqlDbType.Bit).Value = false;
               insertAlalCmd.Parameters.Add("@nightShoot", SqlDbType.Bit).Value = false;
               insertAlalCmd.Parameters.Add("@grenadeOperation", SqlDbType.Bit).Value = false;
               insertAlalCmd.Parameters.Add("@pakalRefresh", SqlDbType.Bit).Value = false;
               insertAlalCmd.Parameters.Add("@targilSufa", SqlDbType.Bit).Value = false;
               insertAlalCmd.Parameters.Add("@firstAid", SqlDbType.Bit).Value = false;
               insertAlalCmd.Parameters.Add("@abcAttack", SqlDbType.Bit).Value = false;
              
               SqlManager.executeNonQuery(insertAlalCmd);

               //add entry to TahasukaZimunim Table
               SqlCommand insertZimunimCmd = SqlManager.getSqlCommandFromFile(@"\INSERT\Mofa.add.soldier.INSERT.sql");
               insertZimunimCmd.CommandText = insertZimunimCmd.CommandText.Replace("Table", "TahasukaZimunim");
               insertZimunimCmd.Parameters.Add("@startDate", SqlDbType.Date).Value = startDate;
               insertZimunimCmd.Parameters.Add("@armyID", SqlDbType.NVarChar).Value = armyID;
               insertZimunimCmd.Parameters.Add("@isDirectiveSent", SqlDbType.NVarChar).Value = false;
               insertZimunimCmd.Parameters.Add("@isApprovedArrival", SqlDbType.NVarChar).Value = false;
               insertZimunimCmd.Parameters.Add("@comments", SqlDbType.NVarChar).Value = System.DBNull.Value;
               SqlManager.executeNonQuery(insertZimunimCmd);
           }
           ZimunumListModified_Fire();
        }
        override public void removeSoldier(List<string> armyIdList)
        {
            foreach (string armyID in armyIdList)
            {
                removeAllSoldierRequests(armyID);
                removeSoldierZimun(armyID);
                removeSoldierFromAlal(armyID);
            }
            ZimunumListModified_Fire();

        }
        private void removeAllSoldierRequests(string armyID)
        {
            SqlCommand removeRequest = SqlManager.getSqlCommandFromFile(@"\DELETE\TahasukaRequests.RemoveAll.DELETE.sql");
            removeRequest.Parameters.Add("@armyID", SqlDbType.NVarChar).Value = armyID;
            removeRequest.Parameters.Add("@startDate", SqlDbType.Date).Value = startDate;
            removeRequest.Parameters.Add("@endDate", SqlDbType.Date).Value = endDate;
            SqlManager.executeNonQuery(removeRequest);
        }
        public void removeSoldierRequest(string armyID, DateTime start, DateTime end)
        {
            SqlCommand removeRequest = SqlManager.getSqlCommandFromFile(@"\DELETE\TahasukaRequest.DELETE.sql");
            removeRequest.Parameters.Add("@armyID", SqlDbType.NVarChar).Value = armyID;
            removeRequest.Parameters.Add("@startRequest", SqlDbType.Date).Value = start;
            removeRequest.Parameters.Add("@endRequest", SqlDbType.Date).Value = end;
            SqlManager.executeNonQuery(removeRequest);
        }
        public void removeSoldierZimun(string armyID) 
        {
            SqlCommand removeSoldierZimun = SqlManager.getSqlCommandFromFile(@"\DELETE\TahasukaZimunim.DELETE.sql");
            removeSoldierZimun.Parameters.Add("@startDate", SqlDbType.Date).Value = startDate;
            removeSoldierZimun.Parameters.Add("@armyID", SqlDbType.NVarChar).Value = armyID;
            SqlManager.executeNonQuery(removeSoldierZimun);
        }
        private void removeSoldierFromAlal(string armyID) 
        {
            SqlCommand removeSoldierAlal = SqlManager.getSqlCommandFromFile(@"\DELETE\TahasukaAlal.DELETE.sql");
            removeSoldierAlal.Parameters.Add("@startDate", SqlDbType.Date).Value = startDate;
            removeSoldierAlal.Parameters.Add("@armyID", SqlDbType.NVarChar).Value = armyID;
            SqlManager.executeNonQuery(removeSoldierAlal);
        }
        public void addRequest(List<string> armyIdList)
        {
            SqlCommand insertCmd = SqlManager.getSqlCommandFromFile(@"\INSERT\TahasukaRequests.INSERT.sql");
            insertCmd.Parameters.Add("@armyID", SqlDbType.NVarChar);
            insertCmd.Parameters.Add("@start", SqlDbType.Date).Value = startDate; 
            insertCmd.Parameters.Add("@finish", SqlDbType.Date).Value = endDate;
            insertCmd.Parameters.Add("@comments", SqlDbType.NVarChar).Value = DBNull.Value;
            
            foreach (string armyID in armyIdList)
	        {
        	    insertCmd.Parameters["@armyID"].Value = armyID;
	            SqlManager.executeNonQuery(insertCmd);
	        }

        }
        public void removeRequests(string armyIdList) { }
        public void removeRequests(List<int> requestIDList) 
        {
            SqlCommand deleteCmd = SqlManager.getSqlCommandFromFile(@"\DELETE\TahasukaRequests.DELETE.sql");
            deleteCmd.Parameters.Add("@requestID", SqlDbType.NVarChar);

            foreach (int id in requestIDList)
            {
                deleteCmd.Parameters["@requestID"].Value = id;
                SqlManager.executeNonQuery(deleteCmd);
            }
        }
    }

    
    /*public class Practice : Mofa
    {
        public Practice(DateTime start, DateTime end)
            : base(start, end, "PracticeData"){}

       override public void addSoldiers(List<string> armyIdList)
       {
            foreach (string armyID in armyIdList)
            {
                SqlCommand insertZimunimCmd = SqlManager.getSqlCommandFromFile(@"\INSERT\Mofa.add.soldier.INSERT.sql");
                insertZimunimCmd.CommandText = insertZimunimCmd.CommandText.Replace("Table", "PracticeZimunim");
                insertZimunimCmd.Parameters.Add("@startDate", SqlDbType.Date).Value = startDate;
                insertZimunimCmd.Parameters.Add("@armyID", SqlDbType.NVarChar).Value = armyID;
                SqlManager.executeNonQuery(insertZimunimCmd);
            }

       }
       

    }*/
}
